# 激活码生成
def code_create():
    import random
    global codes
    code = []
    codes = ""
    for i in range(32):
        # 随机从0-9生成一位数字
        add_num = str(random.randrange(0, 9))
        # 百度 chr转换为A-Z大写。print(chr(90))#65-90任意生成A-Z
        add_alpha = chr(random.randrange(65, 90))
        # 百度 为了保证概率，将数字写入两遍，这样，字母和数字概率一样了
        activation_code = random.choice([add_num, add_alpha, add_num])
        # 将随机生成数字存入列表
        code.append(activation_code)
        # 将列表的连接成一个激活码
        codes = ("".join(code))
    # print(codes)


def main():
    num = input("请输入您要生成激活码的个数:")

    result = num.isdigit()
    if result:
        nums = int(num)
        with open("code.txt", "w+") as f:

            for i in range(nums):
                code_create()
                f.write(f'{codes}\n')
    else:
        print("-" * 13)
        print('请输入阿拉伯数字')


main()
